﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Check third digit</title>
    <script src="scripts/isValidInput.js"></script>
    <link href="styles/js-console.css" rel="stylesheet" />
</head>
<body>
    <label for="input">Enter integer:</label>
    <input type="text" id="input" />
    <button onclick="CheckThirdDigit()">
        Check third digit
    </button>

    <div id="js-console"></div>
    <script src="scripts/js-console.js"></script>

    <script>
        //Write an expression that checks for given integer if its third digit (right-to-left) is 7. E. g. 1732 -> true.
        function CheckThirdDigit() {
            var number = parseInt(document.getElementById("input").value);
            if (isValidInputNumber(number)) {
                var digit = parseInt(number / 100) % 10;
                if (digit < 0) digit *= -1;
                jsConsole.write("Third digit is 7 -> ");
                if (digit == 7) {
                    jsConsole.writeLine("true.");
                }
                else {
                    jsConsole.writeLine("false. It is " + digit + ".");
                }
            }
            else {
                jsConsole.writeLine("Enter valid numbers.");
            }
        }
    </script>
</body>
</html>
